import {HANDLER_BLUR,HANDLER_FOUCS,INIT_LIST_DATA,HANDLER_MOUSE_ENTER,HANDLER_MOUSE_LEAVE,CHANGE_PAGE} from '../../../store/actionTypes'
import {fromJS} from 'immutable'
//使用immutable来防止state数据被改变，
const defaultState = fromJS({
    foucs:false,
    list:[],
    pageTotal:0,
    page:1,
    mouseIn:false,
});
export default (state = defaultState,action) =>{
    if(action.type === HANDLER_FOUCS){
        return state.set('foucs',true);
    }
    if(action.type === HANDLER_BLUR){
        return state.set('foucs',false);
    }
    if(action.type === INIT_LIST_DATA){
        //console.log(action.data);
        var pages = Math.ceil(action.length/10)
        return state.set('list',action.data).set('pageTotal',pages);
        //console.log(state.get('list'));
    }
    if(action.type === HANDLER_MOUSE_ENTER){
        return state.set('mouseIn',true);
    }
    if(action.type ===HANDLER_MOUSE_LEAVE){
        return state.set('mouseIn',false);
    }
    if(action.type === CHANGE_PAGE){
        //console.log(action.page);
        return state.set('page',action.page);
    }
    return state;
}
